/*
 * @Author: sjr
 * @Date: 2021-01-31 11:25:05
 * @LastEditTime: 2021-01-31 11:32:55
 * @LastEditors: sjr
 * @Description: 描述
 * @FilePath: \leetcode\101.对称二叉树.js
 */
/*
 * @lc app=leetcode.cn id=101 lang=javascript
 *
 * [101] 对称二叉树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isSymmetric = function(root) {
  if(!root) {
    return true
  }
  const leftAndRight = (left, right) => {
    if(!left && !right) return true
    if(!left || !right) return false
    if(left.val !== right.val) return false
    return leftAndRight(left.left, right.right) && leftAndRight(left.right,right.left)
  }
  return leftAndRight(root.left, root.right)
};
// @lc code=end

